home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 24 / AACD 24.iso / AACD / Sound / LAME / WarpOS / src / API < prev    next >
Encoding:
Text File  |  2001-06-12  |  3.0 KB  |  95 lines

  1. The LAME API
  2.  
  3. This is the simple interface to the encoding part of libmp3lame.so.
  4. The library also contains routines for adding id3 tags and 
  5. mp3 decoding.  These routines are not fully documented,
  6. but you can figure them out by looking at "include/lame.h" and the
  7. example frontend encoder/decoder source code in frontend/main.c
  8.  
  9. All of these steps should be done for every MP3 to be encoded.
  10.  
  11.  
  12. =========================================================================
  13.  
  14. 1. (optional) Get the version number of the encoder, if you are interested.  
  15.    void get_lame_version(char *strbuf, size_t buflen, const char *prefix);
  16.  
  17.  
  18. 2. Error messages.  By default, LAME will write error messages to
  19. stderr using vfprintf().  For GUI applications, this is often a problem
  20. and you need to set your own error message handlers:
  21.  
  22.    lame_set_errorf(gfp,error_handler_function);
  23.    lame_set_debugf(gfp,error_handler_function);
  24.    lame_set_msgf(gfp,error_handler_function);
  25.   
  26. See lame.h for details.
  27.  
  28.  
  29. 3. Initialize the encoder.  sets default for all encoder parameters.
  30.  
  31.    #include "lame.h"
  32.    lame_global_flags *gfp;
  33.    gfp = lame_init();
  34.  
  35. The default (if you set nothing) is a a J-Stereo, 44.1khz
  36. 128kbps CBR mp3 file at quality 5.  Override various default settings 
  37. as necessary, for example:
  38.  
  39.    lame_set_num_channels(gfp,2);
  40.    lame_set_in_samplerate(gfp,44100);
  41.    lame_set_brate(gfp,128);
  42.    lame_set_mode(gfp,1);
  43.    lame_set_quality(gfp,2);   /* 2=high  5 = medium  7=low */ 
  44.  
  45.  
  46. See lame.h for the complete list of options.
  47.  
  48.  
  49.  
  50. 4. Set more internal configuration based on data provided above,
  51.    as well as checking for problems.  Check that ret_code >= 0.
  52.  
  53.    ret_code = lame_init_params(gfp);
  54.  
  55.  
  56.  
  57. 5. Encode some data.  input pcm data, output (maybe) mp3 frames.
  58. This routine handles all buffering, resampling and filtering for you.
  59. The required mp3buffer_size can be computed from num_samples, 
  60. samplerate and encoding rate, but here is a worst case estimate:
  61. mp3buffer_size (in bytes) = 1.25*num_samples + 7200.
  62. num_samples = the number of PCM samples in each channel.  It is
  63. not the sum of the number of samples in the L and R channels.
  64.  
  65. The return code = number of bytes output in mp3buffer.  This can be 0.
  66. If it is <0, an error occured.  
  67.  
  68.    int lame_encode_buffer(lame_global_flags *gfp,
  69.          short int leftpcm[], short int rightpcm[],
  70.          int num_samples,char *mp3buffer,int  mp3buffer_size);
  71.  
  72.  
  73. There are also routines for various types of input  
  74. (float, long, interleaved, etc).  See lame.h for details.
  75.  
  76.  
  77. 6. lame_encode_flush will flush the buffers and may return a 
  78. final few mp3 frames.  mp3buffer should be at least 7200 bytes.
  79. return code = number of bytes output to mp3buffer.  This can be 0.
  80.  
  81. int lame_encode_flush(lame_global_flags *,char *mp3buffer, int mp3buffer_size);
  82.  
  83.  
  84. 7.  Write all remaining data to mp3 file.  If the file was
  85. encoded using VBR and you want to add a Xing VBR header:
  86.  
  87. void lame_mp3_tags_fid(lame_global_flags *,FILE* fid);
  88.  
  89.  
  90. 8. free the internal data structures.
  91.  
  92. void lame_close(lame_global_flags *); 
  93.  
  94.  
  95.